package action;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
//import org.hibernate.classic.Session;
import org.hibernate.Session;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private String username;
	private String password;
	private SessionFactory sessionFactory;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
//		this.sessionFactory.openSession();
	}
	@Override
	public String execute() throws Exception{
		Session session= sessionFactory.openSession();
		String hql="from U u where u.username=? and u.password=?";
		Query query=session.createQuery(hql);
		query.setParameter(0, username);
		query.setParameter(1, password);
		List user=query.list();
		session.close();
		if(user.size()>0){
			return SUCCESS;
		}else{
			return ERROR;
		}
		
	}

}
